<template>
	<view class="page">
		<view class="price-count-down">
			<view class="price">
				<text class="min">￥</text>
				<text class="max">{{price}}</text>
			</view>
			<!-- <view class="count-down">
				<view class="title">支付剩余时间</view>
				<view class="count">
					<text class="time">{{hour}}</text>
					<text class="dot">:</text>
					<text class="time">{{min}}</text>
					<text class="dot">:</text>
					<text class="time">{{sec}}</text>
				</view>
			</view> -->
		</view> 
		<!-- 支付方式列表 -->
		<view class="pay-way">
			<view class="pay-list">
				<view class="list" v-for="(item,index) in PayList" 
				@click="onPayWay(item,index)"
				:key="index">
					<view class="pay-type">
						<image :src="item.icon" mode=""></image>
						<text>{{item.name}}</text>
					</view>
					<view class="check">
						<text class="iconfont" :class="PayWay === index ? 'icon-checked action':'icon-check'"></text>
					</view>
				</view>
			</view>
		</view>
		<view class="pay-submit">
			<view class="submit" @click="tui.dianji(onSubmit)">{{PayPirce}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				PayList: [
					{
						icon: '/static/wx_pay.png',
						name: '微信支付',
					},{
						icon: '/static/zfb_pay.png',
						name: '支付宝支付',
					},{
						icon: '/static/ye_pay.png',
						name: '余额支付',
					},
				],
				PayWay: 0,
				PayPirce: `微信支付￥299.00`,
				CountDown: 1000,
				day: 0,
				hour: 0,
				min: 0,
				sec: 0,
				prcie:0,
				code:'',
				addresscode:'',
				coupon_id:''
			};
		},
		onLoad(e){
			this.code = e.code
			this.price = e.price
			this.addresscode = e.addresscode
			this.coupon_id = e.coupon_id
			this.PayPirce = `微信支付￥${this.price}`
		},
		methods:{
			/**
			 * 支付方式切换点击
			 */
			onPayWay(item,index){
				console.log(item)
				this.PayWay = index;
				this.PayPirce = `${item.name}￥${this.price}`
			},
			/**
			
			/**
			 * 支付点击
			 */
			onSubmit(){
				let that = this
				that.tui.request("api.auth.order/perfect", "post", {order_no:that.code,code:that.addresscode,coupon_id:that.coupon_id}, false,false, true).then((res) => {
					console.log(res)
					that.tui.request("api.auth.order/payment", "post", {order_no:res.data.order_no,payment_code:that.PayWay==2?'M7893204937771106739':'M8052888745606631252'}, false,false, true).then((es) => {
						console.log(es)
						// that.tui.toast('支付成功')
						if(es.code==1){
							that.tui.toast('支付成功')
							setTimeout(function(){
								uni.redirectTo({
									url: '/pages/PayResult/PayResult?price='+that.price+"&zhifu="+that.PayList[that.PayWay].name,
								})
								// uni.redirectTo({
								// 	url:'/pages/shop/order_list?type=2'
								// })
							},1000)
						}else{
							setTimeout(function(){
								uni.redirectTo({
									url:'/pages/shop/order_list?type=1'
								})
							},1000)
						}
					}).catch((res) => {})
					
				}).catch((res) => {})
				
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'CashierDesk.scss';
</style>
